var base = getApp();
Page({
  data: {
    loaded: false,
    mylist: [],
    pagenum: 1,
    oid: 0,
    status: 0,
    url: base.path.url,
    detail: "",
  },
  onLoad: function (e) {
    // 页面初始化 options为页面跳转所带来的参数
    var oid = e.oid;
    var status = e.status;
    var _this = this;
    wx.setNavigationBarTitle({
      title: '订单详情'
    });
    _this.setData({
      oid: oid,
      status: status
    });
    _this.orderList();
  },
  // 评价
  goComment: function (e) {
    var that = this;
    var gid = e.currentTarget.dataset.gid;
    var oid = e.currentTarget.dataset.oid;
    wx.navigateTo({
      url: '../comment/comment?gid=' + gid + '&oid=' + oid,
    })
  },
  // 申请售后
  goService: function (e) {
    var that = this;
    var gid = e.currentTarget.dataset.gid;
    var oid = e.currentTarget.dataset.oid;
    var coid = e.currentTarget.dataset.coid;
    var skuid = e.currentTarget.dataset.skuid;
    wx.redirectTo({
      url: '../service/service?gid=' + gid + '&oid=' + oid + '&coid=' + coid + '&skuid=' + skuid,
    })
  },
  // 去商品详情页
  goPro: function (e) {
    var that = this;
    var gid = parseInt(e.currentTarget.dataset.gid);
    wx.navigateTo({
      url: '../../goods_detail/goods_detail?id=' + gid,
    })
  },
  onShareAppMessage: function () {
    return {
      title: base.user.shareTitle,
      desc: base.user.shareDesc,
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  orderList: function () {
    var that = this;
    wx.request({
      url: base.path.api + 'Member.GetUserOrdersDetail',
      data: {
        md5key: base.user.session_key,
        aid: base.user.aid,
        oid: that.data.oid
      },
      async: false,
      method: "POST",
      header: base.user.header,
      success: function (response) {
        var result = response.data;
        var mylist = {};
        if (result.ret == 200) {
          var mylist = result.data;
          var valname = "";
          for (var j = 0; j < mylist.val_name.length; j++) {
            valname += mylist.val_name[j].attr_name + "：" + mylist.val_name[j].val_name + " "
          }
          mylist.detail = mylist.goods_name + "," + valname;
          that.setData({
            mylist: mylist,
          })

        }

      },
      fail: function (reg) {


      }
    })
  },

  // 确认收货
  bindGoodsOver: function (e) {
    var oid = e.currentTarget.dataset.oid;
    wx.showModal({
      content: '是否确认收货',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: base.path.api + 'Order.ConfirmOrder',
            data: {
              md5key: base.user.session_key,
              order_id: oid
            },
            method: "POST",
            header: base.user.header,
            success: function (response) {
              var result = response.data;
              if (result.ret == 200) {
                wx.showModal({
                  showCancel: false,
                  content: '确认收货成功',
                  success: function (res) {
                    if (res.confirm) {
                      wx.redirectTo({
                        url: '/pages/user/myorder/myorder?ostatus=' + 4,
                      })
                    }
                  }
                })
              }
            }
          })
        } else if (res.cancel) {

        }
      }
    })
  },
  //支付
  bindPay: function (e) {
    var oid = e.currentTarget.dataset.oid;
    var detail = e.currentTarget.dataset.detail;
    base.getPay(oid, detail);
  },
  // 查看物流
  goLogistics: function (e) {
    var that = this;
    var orderno = e.currentTarget.dataset.orderno;
    var skuimg = e.currentTarget.dataset.skuimg;
    wx.navigateTo({
      url: '../logistics/logistics?orderno=' + orderno + '&skuimg=' + skuimg,
    })
  }
})